package cn.day7;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


class Book{
    private int bid;
    private String name;
    private float price;

    public Book(int bid, String name, float price) {
        this.bid = bid;
        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bid=" + bid +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    public void sell(){
        System.out.println(this.name+"被卖了");
    }
    public void sell(float price,String person){
        System.out.println(this.name+"卖给了"+person+"卖了"+price+"元");
    }
}
public class homework {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class c = Book.class;
        Constructor con = c.getConstructor(int.class, String.class,float.class);
        System.out.println(con);
        Book book= (Book) con.newInstance(1,"钢铁是怎样炼成的",70);
        System.out.println(book);
        Method method1=c.getDeclaredMethod("sell");
        Method method2=c.getDeclaredMethod("sell", float.class, String.class);
        method1.setAccessible(true);
        method2.setAccessible(true);
        method1.invoke(book);
        method2.invoke(book,666,"琪琪");
    }
}